/*
 *点击table组件  dialog组件的操作
 */

import { ref } from "vue"
import formDialog from "@/components/from-dialog/form-dialog.vue"
import detailDialog from "@/components/detail-dialog/detail-dialog.vue"

type callbackFnType = (data?: any) => void

function usePageFormDialog(newCallback?: callbackFnType, editCallback?: callbackFnType) {
  const formDialogRef = ref<InstanceType<typeof formDialog>>()
  const detailRef = ref<InstanceType<typeof detailDialog>>()
  function handleNewClick() {
    formDialogRef.value?.setModalVisible()
    if (newCallback) newCallback()
  }
  function handleEditClick(itemData: any) {
    formDialogRef.value?.setModalVisible(false, itemData)
    if (editCallback) editCallback(itemData)
  }
  function handleDetailClick(itemData: any) {
    detailRef.value?.setModalVisible(itemData)
  }

  return {
    formDialogRef,
    detailRef,
    handleNewClick,
    handleEditClick,
    handleDetailClick,
  }
}

export default usePageFormDialog
